<template>
	<view class="Home_content">
		<view class="header">
			<view class="page-section-spacing">
				<swiper class="swiper" autoplay="true" interval="3500" duration="500" circular="true">
					<swiper-item v-for="(item,index) in bannerImg" :key="index" @tap="lbshare(item.hurl,index)">
						<image :src="item.cnimageurl" mode="aspectFill" v-if="languageInitialization=='zh'"></image>
						<image :src="item.enimageurl" mode="aspectFill" v-else></image>
					</swiper-item>
				</swiper>
			</view>
			<view class="Header_navbar">
				<view class="left_box">
					<view class="zhifu" @tap="zhifu">
						<image src="../../static/image/zhifu.png"></image>
						<text>{{ i18n.zhifu }}</text>
					</view>
					<view class="transfer_accounts" @tap="transfer_accounts">
						<image src="../../static/image/zhuanzhang.png"></image>
						<text>{{ i18n.transfer_accounts }}</text>
					</view>
					<view class="Collection" @tap="Collection">
						<image src="../../static/image/shoukuan.png"></image>
						<text>{{ i18n.Collection }}</text>
					</view>
					<view class="send" style="text-align: center;" @tap="hongbao">
						<image src="../../static/image/fahongbao.png" style="width: 136upx;height: 185upx;"></image>
						<text>{{ i18n.send }}</text>
					</view>
				</view>

				<view class="user" @tap="userCenter" v-if="login_status">
					<image src="../../static/image/avator.png" ></image>		
					<text>{{i18n.user1}}</text>
				</view>
				<view class="user" v-else @tap="Login">
					<image src="../../static/image/user_nologin.png"></image>
					<view>
						<text>{{i18n.user2}}</text>
					</view>
				</view>

			</view>
		</view>
		<view class="notice" @tap="announcement">
			<image src="../../static/image/notice.png" class="bjimg"></image>
			<view class="notice_left">
				<image src="../../static/image/notice_icon.png"></image>
				<text>{{i18n.notice_left}}</text>
			</view>
			<image :src="i18n.notice_more" class="notice_more"></image>
		</view>
		<!-- 数字资产 -->
		<view class="number_assets">
			<view class="">
				<image :src="i18n.number_assets" style="margin-top: 38upx;" class="number_assetsimg1"></image>
			</view>
			<view class="" @tap="getmyredgift" :animation="bag1animation">
				<image :src="i18n.redlinghongbaoicon" mode="" style="width: 216upx;height: 151upx;float: right;"></image>
			</view>

		</view>
		<view class="assets">
			<image :src="i18n.bottom1" @tap="assets_exchange"></image>
			<image :src="i18n.bottom2" @tap="assets_manage"></image>
			<image :src="i18n.bottom3" @tap="assets_issue"></image>
			<image :src="i18n.bottom4" @tap="assets_vote"></image>
		</view>
	</view>
</template>

<script>
	import {
		myMixins
	} from '../../common/mixins.js'
	import account from '../../common/account.js'
	export default {
		computed: {
			i18n() {
				return this.$t('user')
			}
		},
		mixins: [myMixins],
		data() {
			return {
				avator: "",
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				accountName: "",
				yqmname: "",
				bannerImg: [],
				languageInitialization: "zh",
				bag1animation: {},
				downover: "",
				rednum:""
			}
		},
		onLoad() {
			this.getUserInfo();
			var _this = this
			if (_this._i18n.locale == "zh_CN") {
				_this.languageInitialization = "zh"
			} else {
				_this.languageInitialization = "en"
			}
				uni.request({				
				url: this.$API.appServeApi + this.$API.getbanner + '?i18n_language=' + uni.getStorageSync('system_info'),
					success(res) {
						if (res.data.code == 200 && res.data.data.length > 0) {
							var bannerlist = res.data.data
							_this.bannerImg=res.data.data
						} else {
						}
				}
				})
									// getredcount
									uni.request({
									url: this.$API.appServeApi + this.$API.getredcount + '?i18n_language=' + uni.getStorageSync('system_info'),
											method: 'GET',
										success(res) {
													_this.rednum=res.data.data
									}
									})
		},
		onShow() {
			var _this = this
			this.login_status = uni.getStorageSync('login_status');
			this.account_info = uni.getStorageSync("account_info");
			uni.getStorage({
				key: 'language',
				success(e) {
					if (e.data) {
						_this.languageInitialization = e.data
					}

				}
			})
			this.imageanimation();
		},

		methods: {
			async accountInfo() {
				//加载账户
				const _this = this;
				await account.getAccount().then(res => {
					_this.accountInfomation = res.data.result;
					_this.accountName = res.data.result.accountName;
					_this.accountID = res.data.result.accountID;
					_this.yqmname = res.data.result.invitationcode
					uni.setStorage({
						key: "accountName",
						data: res.data.result.accountName
					})

				}).catch(error => {
				})
				this.getUserInfo(_this.accountName)
			},
			getUserInfo() {
				//获取手机号
				const _this = this;
				const data = {
					account: this.account_info.accountName
				};
				account.getuserInfo(data).then(res => {
					if (res.code == 200) {
						//_this.phone = _this.$CommonJS.initPhone(res.data.mobile)
						_this.phone = res.data.mobile;
						_this.yqmname = res.data.invitationcode
						_this.accountName = res.data.account
						uni.setStorage({
							key: 'username',
							data: res.data.account,
							success: function() {}
						});
					} else {
					}

				}).catch(error => {
				})
			},
			lbshare(e) {
				if (e.substring(0, 3) == "../") {
					if (this.accountName && this.yqmname) {
						this.login_status ? this.$CommonJS.navigateTo(e + '?yqmname=' + this.yqmname + '&accountName=' + this.accountName) :
							this.$CommonJS.showToast(this._i18n.locale == 'zh_CN' ? '请先登录' : 'Please log in first')
					}
				} else {
					//#ifdef APP-PLUS
					plus.runtime.openURL(e);
					//#endif
					//#ifdef H5
					window.open(e)
					//#endif
				}

			},
			zhifu() {
				//支付
				const _this = this;
				this.login_status ?
					uni.scanCode({
						success: function(res) {
							const d = JSON.parse(res.result);
							if (d.ToaccountName == '' || d.Tocoin_name == '' || d.ToaccountID == '') {
								_this.$CommonJS.showToast(_this._i18n.locale == 'zh_CN' ? '此二维码不能识别' : 'This QR code cannot be recognized');
								return;
							} else if (d.ToaccountName == _this.account_info.accountName) {
								_this.$CommonJS.showToast(_this._i18n.locale == 'zh_CN' ? '非法操作,收款账户为当前账户' :
									'Illegal operation. The collection account is the current account');
								return;
							}
							_this.$CommonJS.navigateTo('../payment/payment?result=' + res.result);
						}
					}) :
					this.$CommonJS.showToast(_this._i18n.locale == 'zh_CN' ? '请先登录' : 'Please log in first')

			},
			transfer_accounts() {
				//转账
				const _this = this
				this.login_status ? this.$CommonJS.navigateTo('../recharge/recharge') : this.$CommonJS.showToast(_this._i18n.locale ==
					'zh_CN' ? '请先登录' : 'Please log in first')
			},
			Collection() {
				const _this = this
				//收款
				this.login_status ? this.$CommonJS.navigateTo('../transfer_accounts/transfer_accounts') : this.$CommonJS.showToast(
					_this._i18n.locale == 'zh_CN' ? '请先登录' : 'Please log in first')
			},
			Login() {
				//登录
				this.$CommonJS.navigateTo('../login/login');
			},
			userCenter() {
				//个人中心
				this.$CommonJS.navigateTo('../me/me')
			},
			announcement() {
				//#ifdef APP-PLUS
				plus.runtime.openURL('https://oexservice.zendesk.com/hc/zh-cn');
				//#endif
				//#ifdef H5
				window.open("https://oexservice.zendesk.com/hc/zh-cn")
				//#endif
			},
			assets_exchange() {
				//资产兑换
				const _this = this
				this.$CommonJS.showToast(_this._i18n.locale == 'zh_CN' ? '敬请期待...' : 'Coming soon...')
			},
			assets_manage() {
				const _this = this
				//资产管理
				this.login_status ? this.$CommonJS.navigateTo('../wallet/wallet') : this.$CommonJS.showToast(_this._i18n.locale ==
					'zh_CN' ? '请先登录' : 'Please log in first')
			},
			assets_issue() {
				const _this = this
				//资产发行
				this.login_status ? this.$CommonJS.navigateTo('../assets_issue/issue') : this.$CommonJS.showToast(_this._i18n.locale ==
					'zh_CN' ? '请先登录' : 'Please log in first')
			},
			assets_vote() {
				const _this = this
				//节点投票
				this.login_status ? this.$CommonJS.navigateTo('../node_vote/node_vote') : this.$CommonJS.showToast(_this._i18n.locale ==
					'zh_CN' ? '请先登录' : 'Please log in first')
			},
			//红包跳转
			hongbao() {
				const _this = this
				if(_this.rednum>100){
							_this.$CommonJS.showToast(_this._i18n.locale =='zh_CN' ? '当前红包分享次数已用尽,次日可体验' : 'The number of red packets shared has been exhausted, and you can experience it the next day')
				}else{
					//红包跳转
					_this.login_status ? this.$CommonJS.navigateTo('../red_envelopes/red_envelopes?sender=' + _this.accountName) : this.$CommonJS.showToast(_this._i18n.locale == 'zh_CN' ? '请先登录' : 'Please log in first')
				}
			
			},
			//领红包页面跳转
			getmyredgift() {
				var _this = this
				this.login_status ? this.$CommonJS.navigateTo('../getmyredgift/getmyredgift?sender=' + _this.accountName) : this.$CommonJS
					.showToast(_this._i18n.locale == 'zh_CN' ? '请先登录' : 'Please log in first')
				// this.login_status ? this.$CommonJS.navigateTo('../22/22?sender=' + _this.accountName) : this.$CommonJS
				// 	.showToast(_this._i18n.locale == 'zh_CN' ? '请先登录' : 'Please log in first')
			},
			// 侧边红包 => 动画
			imageanimation: function() {
				var that = this;
				var next = true;
				var animation = uni.createAnimation({
					duration: 1500,
					timingFunction: 'ease',
				})
				that.bag1animation = animation
				setInterval(function() {
					if (next) {
						animation.rotate(15).step();
						next = !next;
					} else {
						animation.rotate(-15).step();
						next = !next;
					}
					that.bag1animation = animation.export()
				}, 1100)
			},
		}
	}
</script>

<style lang="stylus">
	@import "../../static/stylus/index/index.stylus"
</style>
